*****************************************************************************************************

This folder contains example codes for the PPI Interface(1) between the SD card and Blackfin 
processors.

The SD card is interfaced to Blackfin through the Parallel Peripheral Interface (PPI). The parallel 
port is used so as to implement the bidirectional data/ command protocol of the SD card. It can 
support the 4-bit SD mode. One of the PPI data lines (PPID4) is used for the command/response 
transfer. 

*****************************************************************************************************

EZ-KIT Lite Switch settings:

1. Unpopulate JP2
2. SW13.4 = ON

*****************************************************************************************************

Algorithms for the software
The flowchart given in Figure 12 shows the overall program flow. Each of the steps for Approach I 
has been described in the algorithms below.

Setup N clock cycles to the SD card
1) Disable TMR7 (clock to the SD Card)
2) Configure the core timer to count for a time equal to N SD clock cycles and interrupt
3) Configure TMR7 in PWM out mode for the desired width and period
4) Enable TMR7
5) Enable the core timer
6) Disable the core timer in the core timer ISR

Setup a continuous SD Card clock
1) Disable TMR7 (clock to the SD Card)
2) Configure TMR7 in PWM out mode for the desired width and period.
3) Enable TMR7

Setup a continuous Blackfin clock
1) Disable TMR6 (clock to BF PPI)
2) Configure TMR6 in PWM out mode for the desired width and period.
3) Enable TMR6

Setup N clock cycles to Blackfin PPI for 1FS Receive:
1) Disable TMR6 (clock to BF PPI)
2) Configure the core timer to count for a time equal to N PPI clock cycles and interrupt
3) Configure TMR6 in PWM out mode for the desired width and period.
4) Configure TMR0 in PWM out mode for the desired width, to derive clock source from PPI Clock
5) Enable TMR6 and TMR0
6) Enable the core timer
7) Disable TMR0
8) Disable the core timer and TMR6 in the core timer ISR

Setup N clocks to Blackfin PPI and the SD card
1) Disable TMR7 (clock to the SD card)
2) Configure the core timer to count for a time equal to N clock cycles and interrupt
3) Configure TMR6 in PWM out mode for the desired width and period.
4) Configure TMR7 in PWM out mode for the desired width and period.
5) Enable TMR6 and TMR7
6) Enable the core timer
7) Disable the core timer and TMR6 in the core timer ISR

Setup Command array
CommandBuffer[6][8] is filled up so that the bits of the command word occupy bit 4 of each word. 
For example, the first byte of CMD0 is 0x40. This translates to CommandBuffer [0][7] = 0; 
CommandBuffer [0][6] = 0x10; CommandBuffer [0][5] = 0; CommandBuffer [0][4] = 0; 
CommandBuffer [0][3] = 0; CommandBuffer [0][2] = 0; CommandBuffer [0][1] = 0; 
CommandBuffer [0][0] = 0. CRC7 is calculated for the last byte of each command word.

Setup Transmit data
TransmitData[516][8] is filled up so that the bits of the data occupy bit 0 of each word. For example, 
for a data byte = 0x33, TransmitData[0][7] = 0; TransmitData[0][6] = 0; TransmitData[0][5] = 1; 
TransmitData[0][4] = 1; TransmitData[0][3] = 0; TransmitData[0][2] = 0; TransmitData[0][1] = 1; 
TransmitData[0][0] = 1. CRC16 is calculated for the entire block.

Receive Response
1) Routine to sense the first zero sent by the card
	a. Setup PPID4 as input to interrupt on the falling edge.
	b. Setup a continuous SD clock
	c. Disable continuous clock in the ISR
2) Dummy DMA receive transaction to account for the delay
3) Actual DMA receive
4) Extract Response: Bit 4 of every byte of the response, ResponseBuffer[17][8] is extracted into 
   FinalResponseBuffer[17]

Send Command
1) Send 12 SD Clocks  minimum 8 needed as per the SD Spec
2) Setup command array
3) Setup and enable DMA transmit
4) Setup and enable PPI transmit
5) Setup 4 clocks to Blackfin  for the delay
6) Setup 48 clocks to Blackfin and the card
7) Check for DMA_RUN bit to be cleared and then disable PPI in the ISR

Receive Data
1) Routine to sense the first zero sent by the card
	a. Setup PPID0 as input to interrupt on the falling edge.
	b. Setup a continuous SD clock
	c. Disable continuous clock in the ISR
2) Dummy DMA receive transaction to account for the delay
3) Actual DMA receive
4) Extract Response: Bit 0 of every byte of the response, ReceiveData [517][8] is extracted into FinalReceiveData [514]

Send Data
1) Setup data in the Data buffer
2) Setup and enable DMA transmit
3) Setup and enable PPI transmit
4) Setup 4 clocks to Blackfin  for the delay
5) Setup 4121 clocks to Blackfin and the card
6) Dummy DMA receive for 8 words  workaround for anomaly# 05000401 - PPI Data Signals D0 and D8 do not Tristate After Disabling PPI
7) Routine to sense the first zero sent by the card
	a. Setup PPID0 as input to interrupt on the falling edge.
	b. Setup a continuous SD clock
	c. Disable continuous clock in the ISR
8) Actual DMA receive operation


*****************************************************************************************************